(function () {
  // 描述一个对象的类型
  type myType = {
    name: string;
    age: number;
    gender: "male" | "female";
  };
  // type myType = {};// error

  let p1: myType = {
    name: "Tom",
    age: 18,
    gender: "male",
  };
  console.log(p1);

  // 接口用来定义一个类结构 —— 一个类中应该包含哪些属性和方法
  // 同时接口也可以当成类型声明去使用
  // 接口中的所有属性都不能有实际的值，所有方法都是抽象方法
  interface Person {
    name: string;
    age: number;
  }

  interface Person {
    gender: "male" | "female";

    sayHi(): void;
  }

  let p2: Person = {
    name: "Jerry",
    age: 17,
    gender: "male",

    sayHi() {
      console.log("hi");
    },
  };
  console.log(p2);

  // 实现接口就是使 类 满足 接口的要求
  class MyClass implements Person {
    name: string;
    age: number;
    gender: "male" | "female";
    constructor(name: string, age: number, gender: "male" | "female") {
      this.name = name;
      this.age = age;
      this.gender = gender;
    }
    sayHi() {
      console.log("hi");
    }
  }

  let p3 = new MyClass("Jerry", 17, "male");
  console.log(p3);
  p3.sayHi();

  /* interface someFunction {
    (x: number, y: number): number;
  }

  let add: someFunction = function (x: number, y: number): number {
    return x + y;
  };

  let subtract: someFunction = function (x: number, y: number): number {
    return x - y;
  };

  console.log(add(1, 2)); // 输出 3
  console.log(subtract(2, 1)); // 输出 1 */
})();
